package cn.com.klun.tjy.common.basePojo;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class PageQueryEntitys extends Entitys {
    private static final long serialVersionUID = 1520062757473541274L;
    private Map<String, String> f = new HashMap();
    private int page = 1;
    private int rows = 10;
    private int totalCount = -1;
    private int totalPages;
    private int limit;
    private int offset;
    private List<Entitys> list = null;
    private String[] strArray = null;

    public PageQueryEntitys() {
    }

    public void addF(String paramKey, String value) {
        if (value != null && value.length() > 0) {
            this.f.put(paramKey, value);
        }

    }

    public int getRows() {
        return this.rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    public int getTotalCount() {
        return this.totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    public int getPage() {
        if (this.page < 1) {
            this.page = 1;
        }

        return this.page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getFirst() {
        return (this.getPage() - 1) * this.rows + 1;
    }

    public int getLast() {
        return this.getFirst() + this.rows > this.getTotalCount() ? this.getTotalCount() : this.getFirst() + this.rows - 1;
    }

    public int getTotalPages() {
        int count = (this.totalCount + this.rows - 1) / this.rows;
        return count;
    }

    public void setTotalPages(int totalPages) {
        if (totalPages == 0) {
            totalPages = 1;
        }

        this.totalPages = totalPages;
    }

    public void resetTotalCount(int totalCount) {
        if (totalCount < 0) {
            totalCount = 0;
        }

        int count = (totalCount + this.rows - 1) / this.rows;
        this.setTotalCount(totalCount);
        this.setTotalPages(count);
        if (this.getPage() > this.getTotalPages()) {
            this.setPage(this.getTotalPages());
        }

    }

    public boolean isHasNext() {
        return this.page + 1 <= this.getTotalPages();
    }

    public int getNextPage() {
        return this.isHasNext() ? this.page + 1 : this.page;
    }

    public boolean isHasPre() {
        return this.page - 1 >= 1;
    }

    public int getPrePage() {
        return this.isHasPre() ? this.page - 1 : this.page;
    }

    public int getBeginCount() {
        int beginCount = (this.getPage() - 1) * this.rows;
        if (beginCount >= this.getTotalCount()) {
            int modpageSize = this.getTotalCount() % this.rows;
            if (modpageSize == 0) {
                modpageSize = this.rows;
            }

            beginCount = this.getTotalCount() + 1 - modpageSize;
        }

        return beginCount < 0 ? 0 : beginCount;
    }

    public int getPageRows() {
        return this.rows;
    }

    public Map<String, String> getF() {
        return this.f;
    }

    public void setF(Map<String, String> f) {
        this.f = f;
    }

    public int getLimit() {
        this.limit = this.page * this.rows - this.rows;
        return this.limit;
    }

    public int getOffset() {
        if (this.page >= this.totalPages && this.page != 1) {
            this.offset = this.getBeginCount();
        } else {
            this.offset = this.rows;
        }

        return this.offset;
    }

    public List<Entitys> getList() {
        return this.list;
    }

    public void setList(List<Entitys> list) {
        this.list = list;
    }

    public String[] getStrArray() {
        return this.strArray;
    }

    public void setStrArray(String[] strArray) {
        this.strArray = strArray;
    }

    public void setPageParameters(int rows, int page, int totalCount) {
        this.setRows(rows);
        this.setPage(page);
        this.resetTotalCount(totalCount);
    }
}

